package algo;

import divTools.Converter;

import objects.AccessPoint;
import objects.Client;
import objects.ReferencePoint;

public class FBCM {
	
	/**
	 * Computes the distances between a client and an access point with the friis index of the nearest reference Point
	 * @param client
	 * @param ap
	 * @param refPoint
	 * @return
	 */
	public static Float computeDistance(Client client, AccessPoint ap, ReferencePoint refPoint){
		
		double pt = Converter.dBmToMw(ap.getOutputPower());
		double pr = Converter.dBmToMw(client.getMeasurements().get(ap.getMacAdress()).getPowerValue());
		
		double gr = Converter.dBmToMw(client.getAntennaGain());
		double gt = Converter.dBmToMw(ap.getAntennaGain());
		
		double lambda = (double)300000000 / (double)ap.getFrequency();
		
		double a = (pt / pr) * gr * gt * Math.pow(lambda / (4 * Math.PI), 2);
		
		float friisIndex = refPoint.getMeasurements().get(ap.getMacAdress()).getFriisIndex();
		
		double r = Math.pow(a, 1 / friisIndex);
		
		return (float)r ;	
	}
}
